//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <stdlib.h>
#include <ctype.h>

int __cdecl _wtoi(const wchar_t * string)
{
    int v = 0;
    int neg = 0;
    wchar_t c;

    if (!string) return 0;

    do {
        c = *string++;
    } while (isspace(c));

    if (c == '+')
        c = *string++;
    else if (c == '-') {
        neg = 1;
        c = *string++;
    }

    for (;;) {
        if (c < '0' || c > '9')
            break;
        v = (v * 10) + (int)(c - '0');
        c = *string++;
    }

    if(neg == 1) v = 0 - v;
    return v;
}
